﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.ComponentModel;

using Willson.JsbManager.Idal;
using Willson.JsbManager.Entity;
using Willson.JsbManager.BllEntity;
using Willson.JsbManager.Comm;

namespace Willson.JsbManager.Bll
{
    public class BLLBaseCompanyInfo:BaseBLL
    {
        private ITableXtCompany xt_company_DAL = null;
        private ITableXtEmployee xt_employee_DAL = null;

        public BLLBaseCompanyInfo()
        {
            xt_company_DAL = Reflect<ITableXtCompany>.Create("DAL_table_xt_company", "Willson.JsbManager.Dal");
            xt_employee_DAL = Reflect<ITableXtEmployee>.Create("DAL_table_xt_employee", "Willson.JsbManager.Dal");
        }

        public int GetSumCompanyItem()
        {
            int result = 0;

            IEnumerator<TableXtCompanyEntity> ator = xt_company_DAL.GetAll(false).GetEnumerator();

            while (ator.MoveNext())
            {
                ++result;
            }

            return result;
        }

        public int GetNotRemoveCompanyItem()
        {
            int result = 0;

            IEnumerator<TableXtCompanyEntity> ator = xt_company_DAL.GetAll(false).GetEnumerator();

            while (ator.MoveNext())
            {
                if (ator.Current.Remove == 0)
                    ++result;
            }

            return result;
        }

        public BindingList<BEBaseCompanyInfo> ListAllCompanyInfo()
        {
            BindingList<BEBaseCompanyInfo> list = new BindingList<BEBaseCompanyInfo>();

            IEnumerator<TableXtCompanyEntity> ator = xt_company_DAL.GetAll(false).GetEnumerator();

            while (ator.MoveNext())
            {
                BEBaseCompanyInfo info = new BEBaseCompanyInfo();
                info.Company_id = ator.Current.Id;
                info.Company_name = ator.Current.Name;
                info.Company_address = ator.Current.Address;
                info.Company_telphone = ator.Current.Telphone;

                TableXtEmployeeEntity em = new TableXtEmployeeEntity();
                em = xt_employee_DAL.FindByID(ator.Current.Gm);

                info.Company_gm_name = em.Name;
                info.Company_remove = ator.Current.Remove;

                list.Add(info);
            }

            return list;
        }

    }
}
